HAL Common Use Cases

This chapter covers various use cases for the HAL common driver.

User application in most basic use case

@startuml
' To add a number by line
'autonumber

' Fix order of each column
participant "User application" as part1
participant "Driver HAL" as part2
participant "Driver Cortex" as part3
participant "Driver RCC" as part4
participant "Driver Flash" as part5

part1->part2 : HAL_Init()

part2->part5 : Configure Flash (prefetch, ...)
part5 --> part2

part2->part4 : Get system core clock configuration
part4 --> part2

part2->part2 : Update SystemCoreClock\nglobal variable

part2->part3 : Configure SysTick()
part3 --> part2

part2 --> part1

@enduml

Called functions:

User application configuration of HAL tick frequency

@startuml
' To add a number by line
'autonumber

' Fix order of each column
participant "User application" as part1
participant "Driver HAL" as part2
participant "Driver RCC" as part3

part1->part2 : HAL_Init()
note right
init with default HAL tick frequency (1ms)
end note
part2 --> part1

part1->part2 : HAL_GetTick()
part2 --> part1

part1->part2 : HAL_InitTick()
note right
Use case 1:
change HAL tick frequency
end note

part2 --> part1

part1->part3 : Change system frequency
part3->part2 : HAL_InitTick()
note right
Use case 2:
update HAL tick config to keep
same HAL tick frequency
end note
part2 --> part3
part3 --> part1

@enduml

Called functions:

User application using HAL delay based on SysTick interruption

@startuml
' To add a number by line
'autonumber

' Fix order of each column
participant "User application (thread mode)" as part1
participant "User application (handler mode)" as part2
participant "Driver HAL" as part3
participant "Driver Cortex" as part4
participant "Device HW interruption" as part5

part1->part3 : HAL_Init()

part3->part3 : HAL_InitTick()

part3->part4 : HAL_CORTEX_SYSTICK_SetFreq()
part4 --> part3

part3->part4 : HAL_CORTEX_SYSTICK_SetClkSource()
part4 --> part3

part3->part4 : HAL_CORTEX_NVIC_SetPriority()
part4 --> part3

part5->part2 : IT event: SysTick_Handler()
note right
periodic recurrent event
end note
part2->part3 : HAL_IncTick()
part3 --> part2
part2 --> part5
part5->part2 : IT event: SysTick_Handler()
note right
periodic recurrent event
end note
part2->part3 : HAL_IncTick()
part3 --> part2
part2 --> part5

part1->part3 : HAL_Delay()
note right
tick start
end note
part5->part2 : IT event: SysTick_Handler()
note right
periodic recurrent event
end note
part2->part3 : HAL_IncTick()
part3 --> part2
part2 --> part5
part5->part2 : IT event: SysTick_Handler()
note right
periodic recurrent event
end note
part2->part3 : HAL_IncTick()
part3 --> part2
part2 --> part5
part3 --> part1
note right
tick end
end note

@enduml

Called functions:

User application using HAL tick suspend and resume

@startuml
' To add a number by line
'autonumber

' Fix order of each column
participant "User application (thread mode)" as part1
participant "User application (handler mode)" as part2
participant "Driver HAL" as part3
participant "Driver Cortex" as part4
participant "Device HW interruption" as part5

part1->part3 : HAL_Init()

part3->part3 : HAL_InitTick()

part3->part4 : HAL_CORTEX_SYSTICK_SetFreq()
part4 --> part3

part3->part4 : HAL_CORTEX_SYSTICK_SetClkSource()
part4 --> part3

part3->part4 : HAL_CORTEX_NVIC_SetPriority()
part4 --> part3

part5->part2 : IT event: SysTick_Handler()
note right
periodic recurrent event
end note
part2->part3 : HAL_IncTick()
part3 --> part2
part2 --> part5

part1->part3 : HAL_SuspendTick()
part3--> part1
note left
Here, no more interruption
from SysTick
end note
part1->part3 : HAL_ResumeTick()
part3--> part1

part5->part2 : IT event: SysTick_Handler()
note right
periodic recurrent event
end note
part2->part3 : HAL_IncTick()
part3 --> part2
part2 --> part5

@enduml

Called functions: